package workflowminer.load;

import java.io.File;
import java.io.IOException;
import java.util.Vector;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import workflowminer.domain.VarData;

public class ChartGenerator {

	private String path;

	public ChartGenerator(String thePath) {
		this.path = thePath;
	}

	public void generateBarChart(Vector<VarData> vector) {
		if (vector.size() > 1) {
			CategoryDataset categoryDataset = new DefaultCategoryDataset();
			for (VarData data : vector) {
				((DefaultCategoryDataset) categoryDataset).addValue(data
						.getOcurrencies(), data.getValue(), data.getValue());
			}
			JFreeChart chart = ChartFactory.createBarChart3D("Variable "
					+ vector.get(0).getVarName(), // Title
					"Valores", // X-Axis label
					"Ocurrencies", // Y-Axis label
					categoryDataset, // Dataset
					PlotOrientation.VERTICAL, true, // Show legend
					true, true);
			File f = new File(path);
			try {
				ChartUtilities.saveChartAsJPEG(f, chart, 738, 588);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
